cmake_minimum_required(VERSION 3.10)

#project(serialproxy)

file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/include/SerialProxy.h" DESTINATION ${CMAKE_INCLUDE_PATH})
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/include/SerialPacketManager.h" DESTINATION ${CMAKE_INCLUDE_PATH})

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Os -fPIC")

aux_source_directory(./src SRC)

#include_directories
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../common/include)

#library_directories
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib)

#add_executable(dlt645 ${SRC}) # 生成可执行文件
#add_library(dlt645 STATIC ${SRC}) # 生成静态库
add_library(serialproxy SHARED ${SRC}) # 生成动态库或共享库
SET_TARGET_PROPERTIES(serialproxy PROPERTIES VERSION 1.0.0 SOVERSION 1)

#TARGET_LINK_LIBRARIES(dlt645 xxx.so)

install(TARGETS serialproxy 
        LIBRARY DESTINATION ${CMAKE_LIBRARY_PATH})


add_custom_command(TARGET  serialproxy
        POST_BUILD
        COMMAND echo "serialproxy builded finished."
        COMMAND ${CMAKE_COMPILER_STRIP} "$<TARGET_FILE:serialproxy>"
        #COMMAND ${CMAKE_COMMAND} -E copy  "${CMAKE_CURRENT_SOURCE_DIR}/include/global.h" ${CMAKE_INCLUDE_PATH}/global.h
#        COMMAND ${CMAKE_COMMAND} -E copy  $<TARGET_FILE:serialproxy> ${CMAKE_LIBRARY_PATH}/libserialproxy.so 
#        COMMENT  "serialproxy is install finished"
       )